﻿using Snowflake.Core;
using System;
using System.Collections.Generic;
using System.Text;

namespace HRX.PayCenter.ApplicationCore.Specifications
{
    /// <summary>
    /// Id生成工具
    /// </summary>
    public static class IdGenHelper
    {
        private static readonly IdWorker _idWork;
        static IdGenHelper()
        {
            _idWork = new IdWorker(1, 1);
        }

        /// <summary>
        /// 生成交易订单号
        /// </summary>
        /// <returns></returns>
        public static string GenOrderNo(string flag, DateTime? dt = null)
        {
            dt = dt == null ? DateTime.Now : dt;
            string prefix = dt.Value.ToString("yyyyMMddHHmmss");
            return $"{flag}{prefix}{_idWork.NextId().ToString().Substring(14, 5)}";
        }
    }
}
